package com.shaoshaohuo.app.adapter;

import java.util.List;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.shaoshaohuo.app.R;
import com.shaoshaohuo.app.entity.EcHotSell;
import com.shaoshaohuo.app.utils.ImageLoadUtil;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

public class EcmainGridviewAdapter<T> extends MyBaseAdapter<EcHotSell> {

	public EcmainGridviewAdapter(Context ctx, List<EcHotSell> list, boolean flag) {
		super(ctx, list, flag);
	}

	@Override
	public View getView(int pos, View convertView, ViewGroup group) {
		
		ViewHolder holder;
        if (convertView == null) {
            convertView = View.inflate(context,R.layout.view_ec_main_gv_item, null);
            holder = new ViewHolder();
            holder.imageView = (ImageView) convertView.findViewById(R.id.imageview__image);
            holder.titleText = (TextView) convertView.findViewById(R.id.textview_title);
            holder.dashLineBottom = (ImageView)  convertView.findViewById(R.id.item_bottom_dash);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        int i = (int) Math.ceil(list.size() / 3.0);
		if (pos >=  (i - 1)  * 3) {
			holder.dashLineBottom.setVisibility(View.GONE);
		}
        EcHotSell item = list.get(pos);
        
        ImageLoader.getInstance().displayImage(item.getLogo(), holder.imageView, ImageLoadUtil.build);
        holder.titleText.setText(item.getTitle());
        
		return convertView;
	}
	
	static class ViewHolder{
	    ImageView imageView;
		TextView titleText;
		ImageView dashLineBottom;
	}
	
}
